package net.maku.association.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
import net.maku.association.convert.InterestAssociationCommunityConvert;
import net.maku.association.entity.InterestAssociationCommunityEntity;
import net.maku.association.service.InterestAssociationCommunityService;
import net.maku.association.query.InterestAssociationCommunityQuery;
import net.maku.association.vo.InterestAssociationCommunityVO;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
* 协会社区
*
* @author 阿沐 babamu@126.com
* @since 1.0.0 2025-04-26
*/
@RestController
@RequestMapping("association/community")
@Tag(name="协会社区")
@AllArgsConstructor
public class InterestAssociationCommunityController {
    private final InterestAssociationCommunityService interestAssociationCommunityService;

    @GetMapping("page")
    @Operation(summary = "分页")
    public Result<PageResult<InterestAssociationCommunityVO>> page(@ParameterObject @Valid InterestAssociationCommunityQuery query){
        PageResult<InterestAssociationCommunityVO> page = interestAssociationCommunityService.page(query);

        return Result.ok(page);
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
    public Result<InterestAssociationCommunityVO> get(@PathVariable("id") Long id){
        InterestAssociationCommunityEntity entity = interestAssociationCommunityService.getById(id);

        return Result.ok(InterestAssociationCommunityConvert.INSTANCE.convert(entity));
    }

    @PostMapping
    @Operation(summary = "保存")
    public Result<String> save(@RequestBody InterestAssociationCommunityVO vo){
        interestAssociationCommunityService.save(vo);

        return Result.ok();
    }
}